#!/usr/bin/bash

DIR=~/dotfiles
BACKUP_DIR=~/dotfiles/backup
VIM_DIR=~/.vim

# if backup directory exists, delete it
if [[ -d $BACKUP_DIR ]]; then
    echo "remove current backup and create a new one"
    rm -rf $BACKUP_DIR
fi

mkdir -p $BACKUP_DIR
mkdir $BACKUP_DIR/vim-pack

# link files in dotfile directory into home directory
mv ~/.vimrc $BACKUP_DIR
ln -s $DIR/vimrc ~/.vimrc

mv ~/.tmux.conf $BACKUP_DIR
ln -s $DIR/tmux.conf ~/.tmux.conf

if [ -d $VIM_DIR ]; then
    echo "backup original $VIM_DIR"
    (cd ~/.vim && tar c .) | (cd $BACKUP_DIR/vim-pack &&tar xf -)
    rm -rf ~/.vim
fi
cp -r -s $DIR/vim ~/.vim
# nerdtree install
vim -u NONE -c "helptags ~/.vim/pack/vendor/start/nerdtree/doc" -c q

